﻿#region Header

// MS codename Velocity Distributed Cache Extensions.
// (c) 2009

#endregion


#region Usings

using System;

using Caching.Extensions.Core;
using Caching.Extensions.Core.Impl;

#endregion


namespace Caching.Extension.Core.Tests.Utils
{
    public abstract class SmartCacheTestsBase : CacheTestBase
    {
        protected const string Key = "k1";
        protected const string Value1 = "value 1";
        protected const string Value2 = "value 2";
        protected const string DefaultCacheName = "test";


        private InprocessCache m_localCache;
        private SmartCache m_smartCache;

        internal InprocessCache LocalCache
        {
            get { return m_localCache; }
        }

        internal SmartCache TestCache
        {
            get { return m_smartCache; }
        }


        protected override void PostSetUp()
        {
            base.PostSetUp();
            m_localCache = CreateLocalCache();
            m_smartCache = (SmartCache) CreateSmartCache();
        }


        internal abstract ISmartCache CreateSmartCache();


        protected override void PreTearDown()
        {
            m_smartCache = null;
            m_localCache = null;
            base.PreTearDown();
        }


        internal virtual InprocessCache CreateLocalCache()
        {
            InprocessCache cache = new InprocessCache(TimeSpan.FromSeconds(60));
            //cache.NotificationEvents.Subscribe(new SmartCachePerformanceMonitorSink());
            return cache;
        }


        protected ISmartCache CreateSmartCache(TimeSpan localTimeout, bool checkUpdates)
        {
            SmartCache cache = new SmartCache(DefaultCacheName, LocalCache, localTimeout, MsCache, checkUpdates);
            cache.NotificationEvents.Subscribe(new SmartCachePerformanceMonitorSink());
            return cache;
        }
    }
}